home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / RealTime Graphics ActiveX / DATA.3 / Examples / Delphi / Scroll / ScrollU.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1997-10-20  |  9.1 KB  |  304 lines

  1. unit ScrollU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   OleCtrls, SCROLLX;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     ScrollXCtrl1: TScrollXCtrl;
  12.     ScrollXCtrl2: TScrollXCtrl;
  13.     ScrollXCtrl3: TScrollXCtrl;
  14.     ScrollXCtrl4: TScrollXCtrl;
  15.     ScrollXCtrl5: TScrollXCtrl;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure ScrollXCtrl1OnInternalTimer(Sender: TObject);
  18.     procedure ScrollXCtrl2OnInternalTimer(Sender: TObject);
  19.     procedure ScrollXCtrl3OnInternalTimer(Sender: TObject);
  20.     procedure ScrollXCtrl4OnInternalTimer(Sender: TObject);
  21.     procedure ScrollXCtrl5OnInternalTimer(Sender: TObject);
  22.   private
  23.   procedure BuildGraph1;
  24.   procedure BuildGraph2;
  25.   procedure BuildGraph3;
  26.   procedure BuildGraph4;
  27.   procedure BuildGraph5;
  28.     { Private declarations }
  29.   public
  30.     { Public declarations }
  31.   end;
  32.  
  33. var
  34.   Form1: TForm1;
  35.  
  36. implementation
  37. uses CTWXDEF;
  38. VAR rData1: Array[0..4] of double;
  39.     rData2: Array[0..4] of double;
  40.     rData3: Array[0..4] of double;
  41.     rData4: Array[0..4] of double;
  42.     rData5: Array[0..4] of double;
  43.     nUpdateCounter: INTEGER;
  44.  
  45. {$R *.DFM}
  46.  
  47. procedure TForm1.FormCreate(Sender: TObject);
  48. begin
  49.     BuildGraph1;
  50.     BuildGraph2;
  51.     BuildGraph3;
  52.     BuildGraph4;
  53.     BuildGraph5;
  54. end;
  55.  
  56.  
  57. procedure TForm1.BuildGraph1;
  58.  
  59. begin
  60.     ScrollXCtrl1.SDataEnable [0] :=  TRUE; // enable the 1st data set
  61.     ScrollXCtrl1.SPlotType [0] :=  SCROLLING_LINE_GRAPH;
  62.     ScrollXCtrl1.SDataNumGroups [0] :=  4; // four channels of data
  63.  
  64.         rData1[0] := 2;
  65.         rData1[1] := 4;
  66.         rData1[2] := 6;
  67.         rData1[3] := 8;
  68.     //axis
  69.     ScrollXCtrl1.AxisMax [X_AXIS1] :=  25.0; // x axis from 0 - 25
  70.     ScrollXCtrl1.AxisEnable [X_AXIS2] :=  TRUE; //enable the second x axis
  71.     ScrollXCtrl1.AxisEnable [Y_AXIS2] :=  TRUE; //enable the second x axis
  72.     ScrollXCtrl1.AxisMajorTickInterval [X_AXIS1] :=  5.0; //label every 5 units
  73.  
  74.     //alarm updating
  75.     ScrollXCtrl1.ScrollAlarmMarksEnable [0] :=  TRUE; //enable alarm marks
  76.     ScrollXCtrl1.ScrollLowAlarmEnable [0] :=  TRUE; //enable lo alarm line
  77.     ScrollXCtrl1.ScrollHighAlarmEnable [0] :=  TRUE; //enable hi alarm line
  78.     ScrollXCtrl1.ScrollSetpointEnable [0] :=  TRUE; //enable set point line
  79.  
  80.     //title
  81.     ScrollXCtrl1.TitleString [TITLE1] := 'Scroll Graph';  //graph title
  82.  
  83.     //window
  84.     ScrollXCtrl1.WindowBackgroundColor := C_LIGHTBLUE;  //background color
  85.     ScrollXCtrl1.WindowBorderStyle := RC_HIGH;
  86.  
  87.     //use internal timer
  88.     ScrollXCtrl1.EnableInternalTimer := TRUE;
  89.  
  90. end;
  91.  
  92.  
  93. procedure TForm1.BuildGraph2;
  94. begin
  95.     ScrollXCtrl2.SPlotType [0] :=  SWEEP_GRAPH; //<<constant needed for type
  96.      ScrollXCtrl2.ScrollDirection [0] :=  TRUE; // vertical scrolling
  97.     ScrollXCtrl2.ScrollDirection [1] :=  TRUE; // vertical scrolling
  98.     ScrollXCtrl2.SDataEnable [0] :=  TRUE; // enable the 1st data set
  99.     ScrollXCtrl2.SDataNumGroups [0] :=  2; // two channels of data
  100.     ScrollXCtrl2.SDataEnable [1] :=  TRUE; // enable the 2ND data set
  101.     ScrollXCtrl2.SDataNumGroups [1] :=  1; // one channels of data
  102.  
  103.     //axis attributes
  104.     ScrollXCtrl2.AxisMax [Y_AXIS1] :=  25.0; // Y axis from 0 - 25
  105.     ScrollXCtrl2.AxisMajorTickInterval [Y_AXIS1] :=  5.0;
  106.  
  107.     //font attributes for axis labels
  108.     ScrollXCtrl2.AxisLabelFontStyle [X_AXIS1] :=  TEXT_BOLD;
  109.     ScrollXCtrl2.AxisLabelFontStyle [Y_AXIS1] :=  TEXT_BOLD;
  110.     ScrollXCtrl2.AxisLabelFontSize [X_AXIS1] :=  10;
  111.     ScrollXCtrl2.AxisLabelFontSize [Y_AXIS1] :=  10;
  112.     ScrollXCtrl2.AxisLabelColor [X_AXIS1] :=  RGB_LIGHTBLUE;
  113.         ScrollXCtrl2.AxisLabelColor [Y_AXIS1] :=  RGB_LIGHTBLUE;
  114.         rData2[0] := 10;
  115.         rData2[1] := 15;
  116.  
  117.     ScrollXCtrl2.ScrollSweepLineColor [0] :=  RGB_LIGHTRED; // set color for sweep line
  118.     ScrollXCtrl2.ScrollLineColor [0,0] :=  RGB_YELLOW;
  119.     ScrollXCtrl2.ScrollLineColor [0,1] :=  RGB_WHITE;
  120.     ScrollXCtrl2.ScrollLineColor [1,0] :=  RGB_BLUE;
  121.  
  122.     //title
  123.     ScrollXCtrl2.TitleString [TITLE1] := 'Sweep Graph';
  124.     ScrollXCtrl2.TitleFontStyle [TITLE1] :=  TEXT_BOLD;
  125.     ScrollXCtrl2.TitleFontSize [TITLE1] :=  12;
  126.  
  127.     ScrollXCtrl2.AxisTitleString [X_AXIS1] := 'X Axis Title';
  128.     ScrollXCtrl2.AxisTitleString [Y_AXIS1] := 'Y Axis Title';
  129.  
  130.     //colors
  131.     ScrollXCtrl2.PlotBackgroundColor := RGB_PALEBLUE;
  132.     ScrollXCtrl2.WindowBackgroundColor  := RGB_LIGHTGRAY;
  133.  
  134.     //plotting area
  135.     ScrollXCtrl2.RightPlotArea := 0.92;
  136.     ScrollXCtrl2.BottomPlotArea := 0.8;
  137.  
  138.     //use internal timer
  139.     ScrollXCtrl2.EnableInternalTimer := TRUE;
  140. end;
  141.  
  142.  
  143. procedure TForm1.BuildGraph3;
  144. begin
  145.     ScrollXCtrl3.SPlotType [0] :=  SCROLLING_BAR_GRAPH  ; //<<constant needed for type
  146.     ScrollXCtrl3.SDataEnable [0] :=  TRUE; // enable the 1st data set
  147.     ScrollXCtrl3.ScrollRelReset [0] :=  0.5; //reset to 1/2
  148.         ScrollXCtrl3.ScrollBarWidth[0] := 0.75;
  149.     //axis
  150.     ScrollXCtrl3.AxisMax [Y_AXIS1] :=  15.0; // y axis range -5  to 15
  151.     ScrollXCtrl3.AxisMin [Y_AXIS1] :=  -5.0;
  152.     ScrollXCtrl3.AxisMajorTickInterval [Y_AXIS1] :=  5.0; //label every 5 units
  153.     ScrollXCtrl3.AxisGridEnable [Y_AXIS1] :=  TRUE;
  154.  
  155.         rData3[0] := 7;
  156.  
  157.     //colors
  158.     ScrollXCtrl3.WindowBackgroundColor  := RGB_YELLOW;
  159.  
  160.     //title
  161.     ScrollXCtrl3.TitleFontStyle [TITLE1] :=  TEXT_BOLD;
  162.     ScrollXCtrl3.TitleString [TITLE1] := 'Scrolling Bar';
  163.  
  164.     //internal timer
  165.     ScrollXCtrl3.EnableInternalTimer := TRUE;
  166.  
  167. end;
  168.  
  169.  
  170. procedure TForm1.BuildGraph4;
  171. var
  172.   sLegendStrings, CR: string;
  173. begin
  174.     ScrollXCtrl4.SPlotType [0] :=  VARIABLE_SCROLLING_GRAPH; //<<constant
  175.     ScrollXCtrl4.TitleString [TITLE1] :=  'Variable Scrolling';
  176.     ScrollXCtrl4.SDataEnable [0] :=  TRUE; // enable the 1st data set
  177.     ScrollXCtrl4.SDataNumGroups [0] :=  5; // Groups must = #channels + 1
  178.     ScrollXCtrl4.AxisMax [X_AXIS1] :=  50.0; // x axis from 0 - 50
  179.  
  180.         rData4[0] := 2;
  181.         rData4[1] := 4;
  182.         rData4[2] := 6;
  183.         rData4[3] := 8;
  184.  
  185.     ScrollXCtrl4.ScrollLineColor[0, 0] :=  RGB_GREEN;
  186.     ScrollXCtrl4.ScrollLineColor[0,1] :=   RGB_LIGHTMAGENTA;
  187.     ScrollXCtrl4.ScrollLineColor[0,2] :=   RGB_LIGHTRED;
  188.     ScrollXCtrl4.ScrollLineColor[0,3] :=   RGB_LIGHTBLUE;
  189.  
  190.     ScrollXCtrl4.LeftPlotArea := 0.12;
  191.     ScrollXCtrl4.TopPlotArea  := 0.3;
  192.     ScrollXCtrl4.RightPlotArea := 0.92;
  193.     ScrollXCtrl4.BottomPlotArea := 0.87;
  194.  
  195.     //legends
  196.     CR :=  chr(13); // make CR a carriage return string;
  197.     sLegendStrings := 'Boston' + CR + 'Chicago' + CR + 'Los Angeles' + CR +'Dallas' + CR;
  198.     ScrollXCtrl4.SLegendEnable  := TRUE; //must enable to view!
  199.     ScrollXCtrl4.SLegendLeft  := 0.05;  //establish position
  200.     ScrollXCtrl4.SLegendTop  := 0.08;
  201.     ScrollXCtrl4.SLegendRight  := 0.95;
  202.     ScrollXCtrl4.SLegendBottom := 0.27;
  203.     ScrollXCtrl4.SLegendOrientation  := OR_HORZ; //horizontal
  204.     ScrollXCtrl4.SLegendFontSize  := 8;
  205.      ScrollXCtrl4.SLegendStrings := sLegendStrings;
  206.  
  207.     //colors
  208.     ScrollXCtrl4.WindowBackgroundColor  := RGB_MEDGRAY;
  209.  
  210.     //internal timer
  211.     ScrollXCtrl4.EnableInternalTimer := TRUE;
  212.  
  213. end;
  214.  
  215. procedure TForm1.BuildGraph5;
  216. begin
  217.     ScrollXCtrl5.SPlotType [0] :=  SCROLLING_XY_GRAPH; //<<constant needed for type
  218.     ScrollXCtrl5.SDataNumGroups [0] :=  4; // groups must = #channels * 2
  219.     ScrollXCtrl5.SDataEnable [0] :=  TRUE; // enable the 1st data set
  220.     ScrollXCtrl5.ScrollXYNumPoints [0] :=  100; // 100 pts in the buffer
  221.  
  222.         nUpdateCounter := 0;
  223.     //axis
  224.     ScrollXCtrl5.AxisMin [X_AXIS1] :=  -10.0; // x axis from -10 - 10
  225.     ScrollXCtrl5.AxisMax [X_AXIS1] :=  10.0;
  226.     ScrollXCtrl5.AxisMin [Y_AXIS1] :=  -10.0; // x axis from -10 - 10
  227.     ScrollXCtrl5.AxisMax [Y_AXIS1] :=  10.0;
  228.  
  229.     //color
  230.     ScrollXCtrl5.WindowBackgroundColor  := RGB_PALEBLUE;
  231.  
  232.     //title
  233.     ScrollXCtrl5.TitleString [TITLE1] := 'XY Plot';
  234.  
  235.     //timer
  236.     ScrollXCtrl5.EnableInternalTimer := TRUE;
  237. end;
  238.  
  239.  
  240. procedure TForm1.ScrollXCtrl1OnInternalTimer(Sender: TObject);
  241. var i: integer;
  242. begin
  243.   For i:=0 to 3 do
  244.   begin
  245.     rData1[i] := rData1[i] + (0.5 - random);
  246.   end;
  247.   ScrollXCtrl1.UpdateDynData(0,rData1[0]);
  248. end;
  249.  
  250. procedure TForm1.ScrollXCtrl2OnInternalTimer(Sender: TObject);
  251. var i: INTEGER;
  252. begin
  253.   For i:=0 to 1 do
  254.   begin
  255.     rData2[i] := rData2[i] + 3 * (0.5 - random);
  256.   end;
  257.   ScrollXCtrl2.UpdateDynData(0,rData2[0]);
  258. end;
  259.  
  260. procedure TForm1.ScrollXCtrl3OnInternalTimer(Sender: TObject);
  261. begin
  262.   rData3[0] := rData3[0] + 2 * (0.5 - random);
  263.   ScrollXCtrl3.UpdateDynData(0,rData3[0]);
  264.  
  265. end;
  266.  
  267. procedure TForm1.ScrollXCtrl4OnInternalTimer(Sender: TObject);
  268. var i: integer;
  269. begin
  270.   For i:=0 to 3 do
  271.   begin
  272.     rData4[i] := rData4[i] + (0.5 - random);
  273.   end;
  274.   rData4[4] := 5 * random;    // Random time interval
  275.   ScrollXCtrl4.UpdateDynData(0,rData4[0]);
  276. end;
  277.  
  278.  
  279. procedure TForm1.ScrollXCtrl5OnInternalTimer(Sender: TObject);
  280. var
  281.   rData: array[0..3] of double;
  282.   rMin: double;
  283.   rMax: double;
  284.   rRange: double;
  285.   rUpdateValue: double;
  286.   i, nNumTraces: integer;
  287. begin
  288.   nNumTraces :=  ScrollXCtrl5.SDataNumGroups[0] div 2;
  289.   for i:=0 TO nNumTraces - 1 DO
  290.   begin
  291.     rUpdateValue :=  nUpdateCounter  / 16.0;
  292.         // X value for XY plot
  293.     rData5[i] := 0.95 * 9.0 * sin ( rUpdateValue ) / 2;
  294.         // Y value for XY plot
  295.     rData5[i + nNumTraces] := 0.95 * 9.0 *
  296.        sin(rUpdateValue *1.1 + 0.5 + i * rUpdateValue)/2;
  297.   end;
  298.    nUpdateCounter := nUpdateCounter + 1;
  299.    ScrollXCtrl5.UpdateDynData (0, rData5[0]);
  300.   end;
  301.  
  302.  
  303. end.
  304.